package com.guoxin.part1.chapter4;

/**
 * @author guoxin
 * @date 2019/8/26
 */
public class TicketWindowRunnable implements Runnable {
    private int index = 1;
    private static final int MAX = 50;
    private static Object lock = new Object();

    @Override
    public void run() {
        synchronized (lock) {
            while (index <= MAX) {
                System.out.println(Thread.currentThread().getName() + " 的号码是：" + index++);
            }
        }
    }

    public static void main(String[] args) {
        TicketWindowRunnable twr = new TicketWindowRunnable();
        new Thread(twr, "一号窗口").start();
        new Thread(twr, "二号窗口").start();
        new Thread(twr, "三号窗口").start();
        new Thread(twr, "四号窗口").start();
    }
}
